package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.SubjectMapper;
import com.example.projectcode.model.Subject;
import com.example.projectcode.service.SubjectService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements SubjectService {
    @Override
    public List<Subject> selectAllSubject() {
        return baseMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public Subject selectSubjectBySubId(Integer subid) {
        QueryWrapper<Subject> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("Subid",subid);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public int insertSubject(String subjectName) {
        Subject subject = new Subject();
        subject.setSubname(subjectName);
        return baseMapper.insert(subject);
    }

    @Override
    public int deleteSubjectById(Integer subjectId) {
        return baseMapper.delete(new QueryWrapper<Subject>().eq("Subid",subjectId));
    }

    @Override
    public Subject selectSubjectBySubName(String subjectName) {
        return baseMapper.selectOne(new QueryWrapper<Subject>().eq("Subname",subjectName));
    }
}
